#include <math.h>
#include <iostream>

using std::cout;
using std::endl;

class Point;//类的前向声明

class Line
{
public:
    double distance(const Point &lhs, const Point &rhs);
};

class Point
{
    //2、友元之成员函数
    friend double Line::distance(const Point &lhs, const Point &rhs);
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int = 0, int = 0)" << endl;
    }

    void print() const
    {
        cout << "(" << _ix
             << ", " << _iy
             << ")";
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }
private:
    int _ix;
    int _iy;
};

//2、友元之成员函数
double Line::distance(const Point &lhs, const Point &rhs)
{
    return hypot(lhs._ix - rhs._ix, lhs._iy - rhs._iy);
}

void test()
{
    Point pt1(1, 2);
    cout << "pt1 = ";
    pt1.print();

    cout << endl << endl;
    Point pt2(4, 6);
    cout << "pt2 = ";
    pt2.print();
    cout << endl;

    /* Line line; */
    cout << endl << "两个点之间的距离 " 
         /* << line.distance(pt1, pt2) << endl; */
         << Line().distance(pt1, pt2) << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

